package com.imust.test.manager;

import com.imust.test.Connect;
import com.imust.test.Main;
import com.imust.test.system.UserListView;

import java.awt.event.*;
import java.sql.SQLException;

import javax.swing.*;
// QQ登录监听器
public class ManagerCheck implements ActionListener {
    private JTextField jco_1; // 用来获取QQ账号的对象
    private JPasswordField jpa_1; // 用来获取QQ密码的对象
    private JFrame frame1;

    public ManagerCheck(JTextField jco_1, JPasswordField jpa_1, JFrame frame1) {
        super();
        this.jco_1 = jco_1;
        this.jpa_1 = jpa_1;
        this.frame1 = frame1;

    }
    /**
     * 为登录动作监听事件执行处理
     */
    public void actionPerformed(ActionEvent e) {
        // 1、获取登录的账号和密码
        String name = new String(jco_1.getText());
        String password = new String(jpa_1.getPassword());
        // 创建LoginDao对象
        Connect connect = new Connect();
        // 查询登录用户，如果有此用户并且密码正确则返回true
        Boolean bl_1 =false;
        try {
            bl_1 = connect.findUser_m(name, password);
        } catch (SQLException e1) {
            e1.printStackTrace();
        }
        // 2、判断输入的账号和密码是否正确
        if (bl_1) {
            // 账号正确，先关闭当前JFrame登录窗口

            frame1.dispose();
            JOptionPane.showMessageDialog(null, "登录成功！");
            // 模拟显示登录成功后的QQ窗口
             UserListView.main();
             Main.closemain();
        } else {
            // QQ账号或密码输入错误，弹出提示信息
            JOptionPane.showMessageDialog(null, "你输入的账户名或密码不正确，请重新输入！");
        }
    }
}